package com.example.caorl.jdbcaop.handler.impl;


import com.example.caorl.jdbcaop.domain.Student;
import com.example.caorl.jdbcaop.handler.IResultSetHandler;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

//将List<Student>类型传给父接口，操作后的结果也就返回List<Student>类型
public class StudentHandler implements IResultSetHandler<List<Student>> {
//public class StudentHandler<T> implements IResultSetHandler<T> {

	public List<Student> handle(ResultSet rs) throws Exception {
		List<Student> list=new ArrayList<>();
		while(rs.next()){
			Long id=rs.getLong("id");
			//System.out.println(id);
			String name=rs.getString("name");
			//System.out.println(name);
			Integer age=rs.getInt("age");
			Student stu=new Student(id,name,age);
			list.add(stu);
		}
		return list;
	}

}
